#pragma once

#include <QFuture>
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent>

namespace Util {
typedef  std::function<int()> Func_t;
class AsynHandle : public QObject
{
    Q_OBJECT
public:
    AsynHandle(Func_t funcObj, Func_t finishedFuncObj) {
        QFuture<int> future = QtConcurrent::run(funcObj);
        QObject::connect(&m_futureWatcher, &QFutureWatcher<int>::finished, this, [=](){
            if (m_futureWatcher.result()) {
                finishedFuncObj();
            }
        });

        m_futureWatcher.setFuture(future);
    }
    ~AsynHandle() {}
private:
    QFutureWatcher<int> m_futureWatcher;
};
};
